package bar.dark.lee.common;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.Button;
import bar.dark.lee.BDConstents;

public class BDButton extends Button
{
	public static Typeface tf = null;
	
	public BDButton(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);
		setCustomFont(context, BDConstents.FONT_FILE_NAME);
	}

	public BDButton(Context context, AttributeSet attrs)
	{
		super(context, attrs);
		setCustomFont(context, BDConstents.FONT_FILE_NAME);
	}

	public BDButton(Context context)
	{
		super(context);
		setCustomFont(context, BDConstents.FONT_FILE_NAME);
	}

	public boolean setCustomFont(Context ctx, String asset) 
	{        
		SharedPreferences pref = ctx.getSharedPreferences("pref", Activity.MODE_PRIVATE);
		int fontFlag = pref.getInt(BDConstents.FONT_SETTING, 1);
		
		if (fontFlag == 0)
		{
			;
		}
		else if (fontFlag == 1)
		{
			try 
			{        
				if (tf == null)
				{
					tf = Typeface.createFromAsset(ctx.getAssets(), asset);
				}
			} catch (Exception e) {            
				return false;        
			}        
			
			setTypeface(tf);     
		}
		
		return true;    
	}
}
